package com.fc.app.fcapp.pages.linechart;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;

import com.fc.app.fcapp.CoreFuncKt;
import com.fc.app.fcapp.R;
import com.fc.library.fresco.Util;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;


/**
 * Created by fc on 2017/12/6.
 */

public class VerticalLine extends FrameLayout {
    private Context mContext;
    private FrameLayout.LayoutParams params;
    private FrameLayout writeLayout;

    public VerticalLine(@NonNull Context context) {
        super(context);
        mContext = context;
        initView();
    }

    private void initView() {
        View greenLine = new View(mContext);
        greenLine.setBackgroundColor(Color.GREEN);
        params = new LayoutParams(Util.Div(4),ViewGroup.LayoutParams.MATCH_PARENT);
        params.gravity = Gravity.CENTER;
        addView(greenLine, params);


        writeLayout = new FrameLayout(mContext);
        params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        addView(writeLayout,params);

        View writeLine = new View(mContext);
        writeLine.setBackgroundColor(Color.WHITE);
        params = new LayoutParams(Util.Div(4), ViewGroup.LayoutParams.MATCH_PARENT);
        params.gravity = Gravity.CENTER;
        writeLayout.addView(writeLine, params);

        View writeBall = new View(mContext);
        writeBall.setBackgroundResource(R.mipmap.net_speed_check_write_ball);
        params = new LayoutParams(Util.Div(30), Util.Div(30));
        params.gravity = Gravity.CENTER_HORIZONTAL;
        params.topMargin = Util.Div(500);
        writeLayout.addView(writeBall,params);

    }

    public void anim(){
//        ObjectAnimator animator = ObjectAnimator.ofFloat(writeLayout, "scaleY", 0, 3, 1);
//        animator.setDuration(2000);
//        animator.start();

        ObjectAnimator animator = ObjectAnimator.ofFloat(writeLayout, "translationY",  -200, -10);
        animator.setDuration(2000);
        animator.start();

    }

    public void aniH(final int x, final int nextX){
//
//        CoreFuncKt.runOnUiThread(new Function0<Unit>() {
//            @Override
//            public Unit invoke() {
                ObjectAnimator animator = ObjectAnimator.ofFloat(this, "translationX", x, nextX);
                animator.setDuration(2000);
                animator.start();
//                return null;
//            }
//        });

    }
}
